package com.ymk.cmd;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.bo.rbac.RbacRoleBO;
import com.ymk.bo.rbac.RbacUserRoleBO;
import com.ymk.core.code.cmd.RbacCmdCode;
import com.ymk.service.IRbacUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class RbacUserRoleDelCmd extends ACmd {

    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        RbacRoleBO rbacRoleBO = super.getData(sign, RbacRoleBO.class);
        super.setCreatedData(sign,rbacRoleBO);

        return respSign;
    }

    @Override
    public CmdSign executeMop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        RbacUserRoleBO repData  = super.getData(sign,RbacUserRoleBO.class);

        RbacUserRoleBO rbacUserRoleBO = new RbacUserRoleBO();
        rbacUserRoleBO.setMchId(repData.getMchId());
        rbacUserRoleBO.setUserId(repData.getUserId());
        rbacUserRoleBO.setRoleId(repData.getRoleId());

        this.rbacRoleUserService.del(rbacUserRoleBO);

        respSign.setSource(super.getSource(rbacUserRoleBO));
        return respSign;
    }


    @Override
    public String getCmdCode() {
        return RbacCmdCode.RBAC_USER_ROLE_DEL;
    }

    @Autowired
    private IRbacUserRoleService rbacRoleUserService;

}
